<template>
	<view class="order-list">
		<view class="tabs-wrap">
			<view :style="{'border-bottom': '2rpx solid #efefef'}">
				<u-tabs-swiper :ref="tabDat.ref" :list="tabDat.tabList" :current="tabDat.currTab" :is-scroll="false"
					activeColor="#00c3ce" @change="tabChange">
				</u-tabs-swiper>
			</view>

			<swiper class="tab-swiper-box" :current="tabDat.swiperCurrent" @transition="tabTransition"
				@animationfinish="tabAnimationfinish">
				<swiper-item class="tab-swiper-item">
					<ListTools :showSeBtn="false" :total="tab1.total"
						:sedate="{st: tab1.ps.startTime, et: tab1.ps.endTime}" @selDate="selNoSeDate">
						<template>
							<view class="other-btns">
								<label class="lt-obtn" :class="{'lt-obtn-sel': tab1.findDay == 0}"
									@click="findDgByDay('0')">今天</label>

								<label class="lt-obtn" :class="{'lt-obtn-sel': tab1.findDay == 1}"
									@click="findDgByDay('1')">明天</label>

								<label class="lt-obtn" :class="{'lt-obtn-sel': tab1.findDay == 2}"
									@click="findDgByDay('2')">后天</label>
							</view>
						</template>
					</ListTools>

					<scroll-view :scroll-top="scrollTop" @scroll="scroll" style="height: 80vh;width: 100%;" scroll-y
						@scrolltolower="tabReachBottom" :refresher-enabled="true" :refresher-threshold="80"
						:refresher-background="'#efefef'" :refresher-triggered="tab1.load.triggered"
						@refresherrefresh="downPullRefres">
						<view class="page-box">
							<view class="no-data" v-if="tab1.list.length == 0"><u-empty text="没有订单数据"
									mode="list"></u-empty></view>

							<template v-else>
								<view class="order" v-for="(o, index) in tab1.list" :key="index">
									<view class="top">
										<view class="left">
											<template v-if="o.routeSimpleName">
												<u-icon name="/static/icons/simple-name.png" :size="30"></u-icon>
												<view class="store">{{ o.routeSimpleName }}</view>
											</template>
										</view>
										<view class="right" style="display: flex;">

											<text v-if="o.mergeMarkindex"
												style="font-weight: 700;margin-right: 20rpx;font-size: 30rpx;">合并订单:{{o.mergeMarkindex}}号</text>
											<button v-if="o.helpGathPrice"
												style="line-height: 40rpx; padding: 5rpx 10rpx;width: 160rpx;height: 50rpx;background-color: red;color: #ffffff;font-size: 25rpx;font-weight: 700;margin-right: 10rpx;"
												@click="helpGathPrice(o)">代收二维码</button>

											<label
												v-if="o.isLate == 1 && (o.status.key != 'AL_TRAVEL' && o.status.key != 'COMPLETED')"
												class="c-red">已迟到</label>



											<OrderState v-else :type="1" :stakey="o.status.key"></OrderState>
										</view>
									</view>

									<view class="item">
										<view class="content" :data-obj="o.id" @click="gotoOrderDetail">
											<view class="title" v-html="o.details"></view>
											<u-button @click="makePhoneCall(o)" v-if="o.isBaitui == 1"
												style="margin-right: 10rpx;" shape="square" type="error"
												size="mini">百推:{{o.baituiSignatoryPhone}}</u-button>
											<!-- <view class="title" v-html="o.routeDetail.replace(/@/g, '<br />')"></view> -->
										</view>

										<view class="bottom">
											<view :style="{'border-color': '#f00000', 'color': '#f00000'}" class="btn"
												@click="findAccidentNoticeSetPageList(o)">
												异常报备
											</view>
											<!-- <view class="more" :data-obj="o.id" @click="isMoreBtn">
												<u-icon name="more-dot-fill" color="rgb(203,203,203)"></u-icon>
											</view> -->

											<template v-if="o.status == 'DRIVER_CONFIRMED'">
												<view class="btn" @click="gotoUpdOrder(1, o)">修改时间/地点</view>
												<!-- <view class="btn" @click="gotoUpdOrder(2, o)">临空时间</view> -->
											</template>
											<!-- && staffState=='DEPEND' -->
											<view v-if="o.status == 'DRIVER_READY_RECEIVE' " class="btn"
												:style="{'border-color': '#f00000', 'color': '#f00000'}"
												:data-obj="{i: index, id: o.id}" @click="on_confirmOrder(o)">
												拒绝接单
											</view>
											<view v-if="o.status == 'DRIVER_READY_RECEIVE'" class="btn"
												:style="{'border-color': '#f00000', 'color': '#f00000'}"
												:data-obj="{i: index, id: o.id}" @click="confirmOrder">
												确认接单
											</view>


											<view v-if="o.status == 'DRIVER_CONFIRMED'" class="btn"
												@click="confirmGoMeetCus(o)">
												出发去接客户
											</view>

											<view v-if="o.status == 'START_TAKE_CUS'" class="btn"
												:style="{'border-color': '#008000', 'color': '#008000'}"
												:data-obj="{i: index, etime: o.endTime, orderNum: o.orderNum}"
												@click="e => confirmOrderGo(o)">
												确认出行
											</view>

											<!-- 	<view v-if="o.type == '1' && o.status == 'ON_ROADING'" class="btn"
												:style="{'border-color': '#008000', 'color': '#008000'}"
												:data-obj="{i: index, orderNum: o.orderNum}" @click="confirmOrderBack">
												确认返程
											</view> -->

											<view v-if="o.status == 'ON_ROADING'" class="btn"
												:style="{'border-color': '#00c3ce', 'color': '#00c3ce'}"
												:data-obj="{i: index, orderNum: o.orderNum}"
												@click="e => confirmOrderDownCar(o)">
												确认完团
											</view>

										</view>
										<!-- <view class="bottom" v-if="tab1.oepnMoreBtns.indexOf(o.id) != -1">
											<view class="btn">修改时间</view>
											<view class="btn">修改地点</view>
											<view class="btn">临空时间</view>
										</view> -->
									</view>
								</view>
								<u-loadmore :status="tab1.load.status" :load-text="tab1.load.loadText"
									bgColor="#f2f2f2"></u-loadmore>
							</template>
						</view>
					</scroll-view>
				</swiper-item>

				<swiper-item class="tab-swiper-item">
					<ListTools :total="tab2.total" :sedate="{st: tab2.ps.startTime, et: tab2.ps.endTime}"
						@selDate="selAlSeDate">
					</ListTools>

					<scroll-view @scroll="scroll" :scroll-top="scrollTop" style="height: 80vh;width: 100%;" scroll-y
						@scrolltolower="tabReachBottom" :refresher-enabled="true" :refresher-threshold="80"
						:refresher-background="'#efefef'" :refresher-triggered="tab2.load.triggered"
						@refresherrefresh="downPullRefres">
						<view class="page-box">
							<view class="no-data" v-if="tab2.list.length == 0"><u-empty text="没有订单数据"
									mode="list"></u-empty></view>

							<template v-else>
								<view class="order" v-for="(o, oi) in tab2.list" :key="oi">
									<view class="top">
										<view class="left">
											<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
											<view class="store">{{ o.routeSimpleName }}</view>
										</view>
										<view class="right" style="display: flex;">

											<text v-if="o.mergeMarkindex"
												style="font-weight: 700;margin-right: 20rpx;font-size: 30rpx;">合并订单:{{o.mergeMarkindex}}号</text>
											<button v-if="o.helpGathPrice"
												style="line-height: 40rpx; padding: 5rpx 10rpx;width: 160rpx;height: 50rpx;background-color: red;color: #ffffff;font-size: 25rpx;font-weight: 700;margin-right: 10rpx;"
												@click="helpGathPrice(o)">代收二维码</button>
											<order-state :type="1" :stakey="o.status.key"></order-state>
										</view>
									</view>

									<view class="item">
										<view class="content" :data-obj="o.id" @click="gotoOrderDetail">
											<view class="title" v-html="o.details"></view>
											<u-button @click="makePhoneCall(o)" v-if="o.isBaitui == 1"
												style="margin-right: 10rpx;" shape="square" type="error"
												size="mini">百推:{{o.baituiSignatoryPhone}}</u-button>
											<!-- <view class="title" v-html="o.routeDetail.replace(/@/g, '<br />')"></view> -->
										</view>
									</view>
								</view>
								<u-loadmore :status="tab2.load.status" :load-text="tab2.load.loadText"
									bgColor="#f2f2f2"></u-loadmore>
							</template>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>

		<MyModel v-if="goMeetCusMd.show" :title="'出发询问'" :btnList="goMeetCusMd.btnList" @btnClick="goMeetCusMdClick">
			<template #mm-cont>
				<view :style="{'font-size': '30rpx', 'min-height': '60rpx', 'text-align': 'center'}">确认出发去接客户吗？</view>
			</template>
		</MyModel>

		<MyModel v-if="orderBackMd.show" :title="'确认返程'" :btnList="orderBackMd.btnList" @btnClick="orderBackMdOkClick">
			<template #mm-cont>
				<view>点击[出发返回下车点]：乘客已上车并立即出发直接返回下车点</view>
				<view>点击[直接完团]：提前完团如不在客户完团点将修改为当前地点和时间</view>
			</template>
		</MyModel>

		<MyModel v-if="orderDownCarMd.show" :title="'确认完团'" :btnList="orderDownCarMd.btnList"
			@btnClick="orderDownCarMdOkClick">
			<template #mm-cont>
				<view>点击[强制确认]：提前完团如不在客户完团点将修改为当前地点和时间</view>
			</template>
		</MyModel>
		<MyModel v-if="on_confirmOrderMd.show" :title="'拒绝接单'" :btnList="on_confirmOrderMd.btnList"
			>
			<template #mm-cont>
				<view style="display: flex;">
					<button style="line-height: 40rpx; padding: 5rpx 10rpx;width: 160rpx;height: 50rpx;background-color: #00C3CE;color: #ffffff;font-size: 25rpx;font-weight: 700;margin-right: 10rpx;"
						@click="on_confirmOrderMdOkClick('个人私事')">个人私事</button>
					<button style="line-height: 40rpx; padding: 5rpx 10rpx;width: 160rpx;height: 50rpx;background-color: #00C3CE;color: #ffffff;font-size: 25rpx;font-weight: 700;margin-right: 10rpx;"
						@click="on_confirmOrderMdOkClick('订单冲突')">订单冲突</button>
					<button style="line-height: 40rpx; padding: 5rpx 10rpx;width: 160rpx;height: 50rpx;background-color: #00C3CE;color: #ffffff;font-size: 25rpx;font-weight: 700;margin-right: 10rpx;"
						@click="on_confirmOrderMdOkClick('车辆故障')">车辆故障</button>
					<!-- <u-input v-model="on_confirmOrderMd.obj.reason" :type="'textarea'" :custom-style="{'color': '#00C3CE'}"
						:placeholderStyle="'color: #f000000;'" :clearable="false" :auto-height="true" :height="150"
						:maxlength="200" :placeholder="'请填写备注，最多输入200个字（选填）'" />-->
					</view> 
			</template>
		</MyModel>

		<MyModel v-if="shareMd.show" :title="'订单分享'" :btnList="shareMd.btnList" @btnClick="shareMdClick">
			<template #mm-cont>
				<view>{{shareMd.content}}</view>
			</template>
		</MyModel>

		<u-toast ref="qtoast" />
		<u-icon v-if="old.scrollTop > 300" @tap="goTop"
			style="position: fixed; top: 1000rpx;right: 50rpx;width: 100rpx;height: 100rpx;background-color: #927c7c7d; border-radius: 50%;"
			name="arrow-upward" color="#fff" size="100">
		</u-icon>
		<u-modal @confirm='longin_confirm' v-model="longin_model" :content="longin_text"></u-modal>

		<u-tabbar :list="tabbar"></u-tabbar>
	</view>
</template>

<script>
	import ListTools from '@/components/list-tools/list-tools.vue';
	import MyDateTime from '@/components/my-date-time/my-date-time.vue';
	import MyModel from '@/components/my-model/my-model.vue';
	import OrderState from '@/components/order-state/order-state.vue';
	import {
		post
	} from '@/common/request.js';

	export default {
		components: {
			ListTools,
			MyDateTime,
			MyModel
		},
		onLoad() {

		},
		data() {
			return {
				staffState: '',
				longin_model: false,
				longin_text: '',
				datatimetext: '',
				tabbar: '',
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				// 登录用户信息
				luser: uni.getStorageSync(this.C.luser),

				// tab数据对象
				tabDat: {
					ref: 'orderListTabs',
					tabList: [{
							name: '未完团'
						},
						{
							name: '已完团'
						},
					],
					// 当前激活的tab索引
					currTab: 0,
					// 当前跟随tab的swiper索引（与tab索引对应）
					swiperCurrent: 0
				},
				// 未完团
				tab1: {
					// 请求参数对象
					ps: {
						// 页码, 页大小

						page: {
							pageNum: '1',
							pageSize: '30',
						},
						// 开始时间
						startTime: '', //this.U.getMonthFirstDay(new Date(), 1).split(' ')[0], 
						// 结束时间
						endTime: '', //this.U.getMonthLastDay(new Date(), 1).split(' ')[0],
						// 数据类型：0-未完团 1-已完团
						isTrip: 0,
					},
					// 列表数组
					list: [],
					// 数据总数
					total: 0,
					// 列表加载更多对象
					load: this.U.scopy(this.C.loadmore),
					// 展开按钮的项
					oepnMoreBtns: [],
					// 查询天数
					findDay: -1
				},
				// 已完团
				tab2: {
					// 请求参数对象
					ps: {
						// 页码, 页大小
						page: {
							pageNum: '1',
							pageSize: '10',
						},
						// 开始时间
						startTime: this.U.getMonthFirstDay(new Date(), 1).split(' ')[0] + ' ' + '00:00:00',
						// 结束时间
						endTime: this.U.getMonthLastDay(new Date(), 1).split(' ')[0] + ' ' + '23:59:59',

						// 数据类型：0-未完团 1-已完团
						isTrip: 1,
					},
					// 列表数组
					list: [],
					// 数据总数
					total: 0,
					// 列表加载更多对象
					load: this.U.scopy(this.C.loadmore),
					// 展开按钮的项
					oepnMoreBtns: [],
				},

				// 出发去接客户按钮
				goMeetCusMd: {
					show: false,
					btnList: [{
							text: '点错取消',
							sty: {
								'background': '#ffffff',
								'color': '#00c3ce',
								'padding': '0 20rpx !important',
								'margin': '0 20rpx'
							}
						},
						// {text: '仅出发', sty: {'background': '#ffffff', 'color': '#00c3ce', 'padding': '0 20rpx !important', 'margin': '0 20rpx'}},
						{
							text: '确认',
							sty: {
								'background': '#00c3ce',
								'color': '#ffffff',
								'padding': '0 20rpx !important',
								'margin': '0 20rpx'
							}
						},
					],
					obj: null
				},
				// 确认返程按钮
				orderBackMd: {
					show: false,
					btnList: [{
							text: '出发返回下车点',
							sty: {
								'background': '#00c3ce',
								'color': '#ffffff',
								'padding': '0 20rpx !important'
							}
						},
						{
							text: '直接完团',
							sty: {
								'background': '#ffffff',
								'color': '#00c3ce',
								'padding': '0 20rpx !important'
							}
						},
						{
							text: '取消',
							sty: {
								'background': '#ffffff',
								'color': '#00c3ce',
								'padding': '0 20rpx !important'
							}
						},
					],
					obj: null
				},
				// 确认完团按钮
				orderDownCarMd: {
					show: false,
					btnList: [{
							text: '强制确认',
							sty: {
								'background': '#00c3ce',
								'color': '#ffffff',
								'padding': '0 20rpx !important'
							}
						},
						{
							text: '取消',
							sty: {
								'background': '#ffffff',
								'color': '#00c3ce',
								'padding': '0 20rpx !important'
							}
						},
					],
					obj: null
				},
				// 拒绝接单按钮
				on_confirmOrderMd: {
					show: false,
					// btnList: [{
					// 		text: '确认拒绝',
					// 		sty: {
					// 			'background': '#00c3ce',
					// 			'color': '#ffffff',
					// 			'padding': '0 20rpx !important'
					// 		}
					// 	},
					// 	{
					// 		text: '取消',
					// 		sty: {
					// 			'background': '#ffffff',
					// 			'color': '#00c3ce',
					// 			'padding': '0 20rpx !important'
					// 		}
					// 	},
					// ],
					obj: {
						id: '',
						reason: '',
					}
				},

				// 分享弹框
				shareMd: {
					show: false,
					// 弹框内容
					content: '',
					btnList: [{
							text: '取消',
							sty: {
								'background': '#ffffff',
								'color': '#00c3ce',
								'padding': '0 20rpx !important',
								'margin': '0 20rpx'
							}
						},
						{
							text: '分享',
							openType: 'share',
							sty: {
								'background': '#00c3ce',
								'color': '#ffffff',
								'padding': '0 20rpx !important',
								'margin': '0 20rpx'
							}
						},
					]
				},

			};
		},
		mounted() {
			this.tabbar = [{
					iconPath: "/static/tabbar/order.png",
					selectedIconPath: "/static/tabbar/order-sel.png",
					text: '订单',
					isDot: false,
					pagePath: "/pages/tabbar/order-list/order-list"
				},
				{
					iconPath: "/static/tabbar/bz.png",
					selectedIconPath: "/static/tabbar/bz-sel.png",
					text: '报账',
					isDot: false,
					pagePath: "/pages/tabbar/order-bz-list/order-bz-list"
				}, {
					iconPath: "/static/tabbar/user.png",
					selectedIconPath: "/static/tabbar/user-sel.png",
					text: '我的',
					isDot: false,
					pagePath: "/pages/tabbar/my/my"
				}
			]

			const that = this;
			that.staffState = uni.getStorageSync('staffState'),
				// 禁用右上角的分享，但可以使用手动触发分享
				uni.hideShareMenu();

			that.getNoOrderList(1);
			that.getAlOrderList(1);

			// 其他页面跳转回当前页刷新列表
			uni.$on('refOrderList', () => {
				that.$nextTick(function() {
					that.getNoOrderList(1);
					that.getAlOrderList(1);
				});
			});

			// uni.request({
			//     url: 'https://www.example.com/request', //仅为示例，并非真实接口地址。
			//     data: {
			//         text: 'uni.request'
			//     },
			//     header: {
			//         'token': 'hello222222' //自定义请求头信息
			//     },
			//     success: (res) => {
			//         console.log(res.data);
			//         this.text = 'request success';
			//     }
			// });
		},
		onUnload() {
			// 移除监听
			uni.$off('refOrderList', this.refOrderList);
		},
		methods: {
			longin_confirm() {
				this.longin_model = false

			},
			makePhoneCall(e) {
				let that = this
				let phone = e.baituiSignatoryPhone
				uni.makePhoneCall({
					phoneNumber: phone,
					success: () => {
						console.log("成功拨打电话")

						let ps = {
							orderNum: e.orderNum,
							phone: phone
						};
						that.$u.api.driverCallCus(ps).then(res => {
							if (res.code == 1) {
								console.log("拨打记录成功");
							}
						});
					}
				});
			},
			scroll: function(e) {
				console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			goTop: function(e) {
				let that = this
				// 解决view层不同步的问题
				console.log(e, '122222')
				that.scrollTop = that.old.scrollTop

				that.$nextTick(function() {
					that.scrollTop = 0
					console.log(that.scrollTop, '122222')
				});


			},
			// 异常报备
			findAccidentNoticeSetPageList(e) {
				uni.removeStorage({
					key: 'phone',

				});

				let phone = {
					mobile: e.mobile,
					dispatchMobile: e.dispatchMobile
				}
				uni.setStorage({
					key: 'phone',
					data: phone,

				});
				uni.navigateTo({
					url: '/order-man/findAccidentNoticeSet/findAccidentNoticeSet?orderNum=' + e.orderNum + '&id=' +
						e.id
				})
			},
			// 代收二维码
			helpGathPrice(e) {
				let helpGathUrl = e.helpGathUrl
				let helpGathPrice = e.helpGathPrice
				if (e.confirmHelpGathUrl) {
					return uni.showToast({
						title: '已确认代收',
						duration: 2000,
						icon: 'none',
					});
				}
				uni.navigateTo({
					url: '/order-man/helpGath/helpGath?helpGathUrl=' + helpGathUrl + '&helpGathPrice=' +
						helpGathPrice + '&id=' + e.id + '&confirmHelpGathUrl=' + e.confirmHelpGathUrl
				})
			},
			/**
			 * 分享小程序页面
			 * @param {Object} o 参数对象，包含分享标题-title，订单编号-orderNum
			 */
			initMpShare(o) {
				const that = this;

				// 小程序-分享
				that.$u.mpShare = {
					// eg：已接杜伟5人出发预计16.30分在芳华酒店完团！
					title: o.title || '分享订单标题',
					// 默认为当前页面路径，一般无需修改，QQ小程序不支持
					path: '/order-man/order-detail/order-detail?orderNum=' + o.orderNum + '&id=' + o.id,
					// 分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径。
					// 支持PNG及JPG，默认为当前页面的截图
					// imageUrl: `${that.C.staticNetUrl}/share-order-img.png`
				}
			},

			// 打开/关闭-分享弹框
			setShareMd(e) {
				const that = this,
					md = that.shareMd,
					ps = e.ps;

				if (e.show) { // 打开弹框
					// 请求接口，获取分享标题
					if (that.datatimetext) {
						ps.endTime = that.datatimetext
					}
					that.$u.api.getOrderShareTitle(ps).then(res => {
						console.log('确认出行-分享标题：', res);

						// 存在标题才初始化
						if (res.data) that.initMpShare({
							title: res.data,
							orderNum: ps.orderNum,
							id: ps.id,
						});
					});

					// 提示内容
					if (ps.operType == 0) {
						md.content = '确认出行成功，立即去分享吧！';
					} else if (ps.operType == 1) {
						md.content = '确认完团成功，立即去分享吧！';
					}

					// 打开弹框
					md.show = true;
				} else { // 关闭弹框
					md.show = false;
				}
			},

			// 分享弹框点击事件
			shareMdClick(index) {
				const that = this,
					U = that.U,
					md = that.shareMd;
				console.log('点击的index', index);

				if (index === 0) {
					md.show = false;
				} else if (index === 1) {
					console.log('点击了分享');

					setTimeout(function() {
						md.show = false;
					}, 800);
				}
			},

			// tabs通知swiper切换
			tabChange(index) {
				let that = this,
					tabs = that.tabDat;

				tabs.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			tabTransition({
				detail: {
					dx
				}
			}) {
				let that = this,
					tabs = that.tabDat;

				that.$refs[tabs.ref].setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			tabAnimationfinish({
				detail: {
					current
				}
			}) {
				let that = this,
					tabs = that.tabDat;

				that.$refs[tabs.ref].setFinishCurrent(current);
				tabs.swiperCurrent = current;
				tabs.currTab = current;
			},
			// 下拉刷新
			downPullRefres() {
				let that = this,
					currTab = that.tabDat.currTab;

				if (currTab == 0) { // 未完团
					that.getNoOrderList(1);
				} else if (currTab == 1) { // 已完团
					that.getAlOrderList(1);
				}
			},
			// 设置-底部上滑加载数据时状态显示
			tabReachBottom() {
				let that = this,
					currTab = that.tabDat.currTab,
					tab = that[`tab${currTab+1}`];

				// 数据已经加载完
				if (tab.list.length == tab.total) {
					// 设置加载状态为：没有更多了
					tab.load.status = 'nomore';
				} else {
					// 设置加载状态为：加载中...
					tab.load.status = 'loading';
					// 增加一页页码
					tab.ps.page.pageNum++;

					if (currTab == 0) { // 未完团
						that.getNoOrderList();
					} else if (currTab == 1) { // 已完团
						that.getAlOrderList();
					}
				}
			},
			// 导航-订单详情
			gotoOrderDetail(e) {
				let id = e.currentTarget.dataset.obj;

				uni.navigateTo({
					url: '/order-man/order-detail/order-detail?id=' + id
				})
			},
			// 日期选择事件回调
			selNoSeDate(e) {
				// console.log('起止日期选择事件', e);

				this.tab1.ps.startTime = e.st;
				this.tab1.ps.endTime = e.et;

				// 重新查询
				this.getNoOrderList(1);
			},
			// 是否打开更多按钮
			isMoreBtn(e) {
				let that = this,
					U = that.U,
					tab = that.tab1;
				let id = e.currentTarget.dataset.obj;

				let is = tab.oepnMoreBtns.findIndex(it => it == id);
				if (is != -1) {
					tab.oepnMoreBtns.splice(is, 1);
				} else {
					tab.oepnMoreBtns.push(id);
				}
			},
			// 查询指定天数的数据
			findDgByDay(day) {
				let that = this,
					U = that.U,
					currTab = that.tabDat.currTab,
					tab = that[`tab${currTab+1}`];
				day = parseInt(day);

				if (tab.findDay == day) {
					// 再次点击则取消
					tab.findDay = -1;

					tab.ps.startTime = U.getMonthFirstDay(new Date(), 1).split(' ')[0] + ' ' + '00:00:00';
					tab.ps.endTime = U.getMonthLastDay(new Date(), 1).split(' ')[0] + ' ' + '23:59:59';

					that.downPullRefres();
				} else {
					tab.findDay = day;

					tab.ps.startTime = U.getSEToday(day)[0];
					tab.ps.endTime = U.getSEToday(day)[1];
					// console.log('起止时间', tab.ps.startTime, tab.ps.endTime);
					that.downPullRefres();
				}
			},
			/**
			 * 获取-未完团-数据列表
			 */
			getNoOrderList(page) {
				let that = this,
					U = that.U,
					tab = that.tab1,
					ps = tab.ps;


				that.longin_text = uni.getStorageSync('longin_text');
				if (that.longin_text) {
					that.longin_model = true
				} else {
					that.longin_model = false
				}
				// 存在，则表示刷新
				if (page) {
					// 开始刷新
					tab.load.triggered = true;
					ps.page.pageNum = 1;
				}
				that.$u.api.getNoOrderList(ps).then(res => {
					// 第一页的时候，停止刷新
					if (page) {
						// 停止刷新
						tab.load.triggered = false;
						// 刷新则清空列表
						tab.list = [];
					}

					if (res && res.data) {
						let list = res.data.list;
						// 追加数据
						tab.list = tab.list.concat(list);


						let new_list = tab.list
						let indxe = 1
						let mergeMark_list = []
						for (let i = 0; i < new_list.length; i++) {
							if (new_list[i].groupNum) {
								mergeMark_list.push(new_list[i].groupNum)
							}
						}

						for (let i = 0; i < mergeMark_list.length - 1; i++) {
							for (let j = i + 1; j < mergeMark_list.length; j++) {
								if (mergeMark_list[i] == mergeMark_list[j]) {
									mergeMark_list.splice(j, 1)
									j--
								}
							}
						}

						for (let a = 0; a < new_list.length; a++) {
							if (new_list[a].groupNum) {
								for (let b = 0; b < mergeMark_list.length; b++) {
									if (new_list[a].groupNum == mergeMark_list[b]) {
										new_list[a].mergeMarkindex = b + 1
									}
								}
							}

						}
						console.log(new_list, '未完团new_list')
						tab.list = new_list



						// 设置总条数
						tab.total = res.data.total;

						// 设置加载状态
						tab.load.status = tab.list.length == tab.total ? 'nomore' : 'loadmore';
					}
				});
			},
			/** 确认接单 */
			confirmOrder(event) {
				const that = this,
					U = that.U,
					tab = that.tab1;

				let obj = event.currentTarget.dataset.obj;

				U.qconfim('确认接单吗？', (e) => {
					if (e.confirm) {


						let ps = {
							id: obj.id,
							isAgree: 1
						};

						U.qloading('确认中...');
						that.$u.api.confirmOrder(ps).then(res => {
							if (res.code == 1) {
								U.qtsuccess('您已确认接单，请尽快联系乘客确认！', that);

								// 刷新订单列表
								that.getNoOrderList(1);
							} else {
								U.qterror(res.msg, that);
							}
						});
					}
				});
			},
			/** 拒绝接单 */
			on_confirmOrder(event) {
				const that = this
				// let obj = event.currentTarget.dataset.obj;
				that.on_confirmOrderMd.obj.id = event.id,
				that.on_confirmOrderMd.obj.reason ='',
				that.on_confirmOrderMd.show = true
				
			},
			on_confirmOrderMdOkClick(index){
				const that = this,					U = that.U,					md = that.on_confirmOrderMd;				uni.showLoading({					title: '加载中'				});				console.log('点击的index', index);								let isBack = -1;				if (index == 1) { // 取消					md.show = false;					uni.hideLoading();				} else {					// 获取-确认返程					let ps = {						id: that.on_confirmOrderMd.obj.id,
						reason: index,					};					that.$u.api.driverRefuseOrder(ps).then(res => {						uni.hideLoading();						md.show = false;						if (res.code == 1) {							U.qtsuccess(res.msg, that);							// 刷新订单列表							that.getNoOrderList(1);													} else {							U.qterror(res.msg, that);						}					}).catch(err => {						uni.hideLoading();						md.show = false;					});				}
			},
			// 确认订单出行
			confirmOrderGo(obj) {
				const that = this,
					U = that.U,
					C = that.C,
					tab = that.tab1;

				console.log('obj', obj);

				// 验证用户是否开启位置权限
				U.valLocationSet(function() {
					// 从缓存中获取当前位置信息
					let location = uni.getStorageSync(C.location);
					if (!location) {
						U.qinfo('获取位置失败，请重新点击');

						U.getLocation(); // 重新获取位置信息
					} else {

						U.qconfim('确认订单出行吗？', (e) => {
							if (e.confirm) {
								let lnglat = location.lng + ',' + location.lat;
								let ps = {
									orderNum: obj.orderNum,
									lnglat: lnglat,
									id: obj.id,
									arrivePlace: 'START_PLACE',
								};

								that.$u.api.valArrSpOrEp(ps).then(res => {
									let text = '',
										okBtnText = '',
										arriveState = -1;
									console.log(res)
									if (res.code == 4) {
										ps = {
											...ps,
											arriveState: 4
										};

										that.$u.api.confirmOrderGo(ps).then(res => {
											if (res.code == 1) {
												// U.qtsuccess(res.msg, that);
												taht.datatimetext = res.data
												// 刷新订单列表
												that.getNoOrderList(1);

												// 打开分享弹框
												that.setShareMd({
													show: true,
													ps: {
														operType: 0,
														orderNum: obj.orderNum,
														id: obj.id,
														arrivePlace: 'START_PLACE',
													}
												});
											} else {
												U.qterror(res.msg, that);
											}
										});
									} else {
										if (res.code == 1) {
											// 已到达起点
											arriveState = 1;
											text = '请根据实际情况操作！';
											okBtnText = '立即出发';
										} else if (res.code == 0) {
											// 未到达起点
											arriveState = 0;
											// text = '点击[强制确认]行程起点将修改为当前位置！';
											text = res.msg;
											okBtnText = '强制确认';
										} else {
											// 未到达起点
											arriveState = -1;
											// text = '点击[强制确认]行程起点将修改为当前位置！';
											text = res.msg;
											okBtnText = '强制确认';
										}

										ps = {
											...ps,
											arriveState
										};
										console.log('1111')
										U.qmodal({
											title: '确认出行',
											text: text,
											cancelText: okBtnText,
											cancelColor: '#00c3ce',
											okText: '取消',
											okColor: '#666666',
											success: function(e) {
												console.log(JSON.stringify(ps), 'ps')
												if (e.cancel) {
													that.$u.api.confirmOrderGo(ps)
														.then(res => {
															if (res.code == 1) {
																// U.qtsuccess(res.msg, that);

																// 刷新订单列表
																that.getNoOrderList(
																	1);

																// 打开分享弹框
																that.setShareMd({
																	show: true,
																	ps: {
																		operType: 0,
																		orderNum: obj
																			.orderNum,
																		id: obj
																			.id,
																		arrivePlace: 'START_PLACE',

																	}
																});
															} else {
																U.qterror(res.msg,
																	that);
															}
														})
												}
											},
											fail: function(e) {
												console.log('333')
												console.log('错误', e);
											}
										});
									}
								});

							}
						});




						// 123
					}
				});
			},
			// 确认订单返程-按钮点击事件
			confirmOrderBack(event) {
				const that = this,
					U = that.U,
					C = that.C,
					tab = that.tab1;

				U.qconfim('确认返程吗？', (e) => {
					if (e.confirm) {
						let obj = event.currentTarget.dataset.obj;

						// 验证用户是否开启位置权限
						U.valLocationSet(function() {
							// 从缓存中获取当前位置信息
							let location = uni.getStorageSync(C.location);
							if (!location) {
								U.qinfo('获取位置失败，请重新点击');

								U.getLocation(); // 重新获取位置信息
							} else {
								// 获取-是否到达[完团地点]
								let ps = {
									orderNum: obj.orderNum,
									lnglat: location.lng + ',' + location.lat,
									id: obj.id,
									// arrivePlace:'START_PLACE',
								};
								that.$u.api.valArrSpOrEp(ps).then(res => {
									// 是否到达：完团地点
									ps.arriveState = res.code == 2 ? 1 : 0;

									that.orderBackMd.show = true;
									that.orderBackMd.obj = ps;
								});
							}
						});
					}
				});



			},
			// [确认返程]弹框项点击选择事件
			orderBackMdOkClick(index) {
				const that = this,
					U = that.U,
					md = that.orderBackMd;
				// console.log('点击的index', index);

				let isBack = -1;
				if (index == 2) { // 取消
					md.show = false;
				} else {
					// 1-出发返回下车点 0-直接完团
					isBack = index == 0 ? 1 : 0;

					// 获取-确认返程
					let ps = {
						...md.obj,
						isBack
					};
					that.$u.api.confirmOrderBack(ps).then(res => {
						md.show = false;

						if (res.code == 1) {
							U.qtsuccess(res.msg, that);

							// 刷新订单列表
							that.getNoOrderList(1);
						} else {
							U.qterror(res.msg, that);
						}
					}).catch(err => {
						md.show = false;
					});
				}
			},
			// 确认订单完团-按钮点击事件
			confirmOrderDownCar(obj) {
				const that = this,
					U = that.U,
					C = that.C;

				U.qconfim('确认订单完团吗？', (e) => {
					if (e.confirm) {
						uni.showLoading({
							title: '加载中'
						});
						// 验证用户是否开启位置权限
						U.valLocationSet(function() {
							// 从缓存中获取当前位置信息
							let location = uni.getStorageSync(C.location);
							if (!location) {
								U.qinfo('获取位置失败，请重新点击');

								U.getLocation(); // 重新获取位置信息
							} else {
								// 获取-是否到达[完团地点]
								let ps = {
									orderNum: obj.orderNum,
									lnglat: location.lng + ',' + location.lat,
									id: obj.id,
									arrivePlace: 'END_PLACE',
								};
								that.$u.api.valArrSpOrEp(ps).then(res => {
									uni.hideLoading();
									if (res.code == 4) {
										ps = {
											...ps,
											arriveState: 4
										};

										that.$u.api.confirmOrderDownCar(ps).then(res => {
											uni.hideLoading();
											if (res.code == 1) {
												// U.qtsuccess(res.msg, that);

												// 刷新订单列表
												that.getNoOrderList(1);
												console.log('确认完成', '1111')
												// 打开分享弹框
												that.setShareMd({
													show: true,
													ps: {
														operType: 1,
														orderNum: obj.orderNum,
														id: obj.id,
														arrivePlace: 'END_PLACE',
													}
												});
												console.log('确认完成', '2222')
											} else {
												U.qterror(res.msg, that);
											}
										});
									} else {
										// 是否到达：完团地点
										ps.arriveState = res.code



										if (ps.arriveState == 1) { // 已到达完团地点
											// 获取-确认返程
											ps = {
												...ps,
												arriveState
											};
											that.$u.api.confirmOrderDownCar(ps).then(res => {
												uni.hideLoading();
												if (res.code == 1) {
													// U.qtsuccess(res.msg, that);

													// 刷新订单列表
													that.getNoOrderList(1);

													// 打开分享弹框
													that.setShareMd({
														show: true,
														ps: {
															operType: 1,
															orderNum: obj.orderNum,
															id: obj.id,
															arrivePlace: 'END_PLACE',
														}
													});
												}
											});
										} else { // 未到达完团地点
											that.orderDownCarMd.show = true;
											that.orderDownCarMd.obj = ps;
										}
									}
								});
							}
						});

					}
				});



			},
			// [确认完团]弹框项点击选择事件
			orderDownCarMdOkClick(index) {

				const that = this,
					U = that.U,
					md = that.orderDownCarMd;
				uni.showLoading({
					title: '加载中'
				});
				// console.log('点击的index', index);

				let isBack = -1;
				if (index == 1) { // 取消
					md.show = false;
					uni.hideLoading();
				} else {
					// 获取-确认返程
					let ps = {
						...md.obj
					};
					that.$u.api.confirmOrderDownCar(ps).then(res => {
						uni.hideLoading();
						md.show = false;

						if (res.code == 1) {
							U.qtsuccess(res.msg, that);
							// 刷新订单列表
							that.getNoOrderList(1);

							// 打开分享弹框
							that.setShareMd({
								show: true,
								ps: {
									operType: 1,
									orderNum: ps.orderNum,
									id: ps.id,
									arrivePlace: 'END_PLACE',
								}
							});

						} else {
							U.qterror(res.msg, that);
						}
					}).catch(err => {

						uni.hideLoading();
						md.show = false;
					});
				}
			},

			/**
			 * 导航-修改订单页面
			 * @param {Object} type 操作类型 1-修改地点/出发时间 2-修改临空时间
			 * @param {Object} obj 	订单
			 */
			gotoUpdOrder(type, obj) {
				// console.log('修改数据', type, obj);

				if (type == 2) { // 修改临空时间
					uni.navigateTo({
						url: '/order-man/upd-empty-time/upd-empty-time?id=' + obj.id
					})
				} else { // 修改订单
					uni.navigateTo({
						url: '/order-man/upd-order/upd-order?id=' + obj.id
					})
					// this.$u.api.getOrderDetail({id: obj.id}).then(res =>{
					//  if(res.code == 1){
					//  	console.log(res)
					//  }
					// })

					// return
					// 	if (obj.dayRoutes.length > 1) {
					// 		uni.navigateTo({
					// 			url: '/order-man/order-day-route-list/order-day-route-list?id=' + obj.id
					// 		})
					// 	} else {
					// 	uni.navigateTo({
					// 		url: '/order-man/upd-order/upd-order',
					// 		success: function(res) {
					// 			let o = obj;
					// 			let d = obj.dayRoutes[0];

					// 			let p = {};
					// 			// 订单编号
					// 			p.orderNum = o.orderNum;
					// 			// 某天行程id
					// 			p.id = d.id;
					// 			// 行程开始时间
					// 			p.startTime = {
					// 				date: d.setime.st.split(' ')[0],
					// 				time: d.setime.st.split(' ')[1]
					// 			};
					// 			// 行程结束时间
					// 			p.endTime = {
					// 				date: d.setime.et.split(' ')[0],
					// 				time: d.setime.et.split(' ')[1]
					// 			};
					// 			// 开始地点
					// 			p.spoint = d.spoint;
					// 			// 上午行程
					// 			p.amps = d.amps || [];
					// 			// 午餐地点
					// 			p.lunchPoint = d.lunchPoint;
					// 			// 下午行程
					// 			p.pmps = d.pmps || [];
					// 			// 结束地点
					// 			p.epoint = d.epoint;
					// 			// 将当前修改的天数行程传递给修改页面
					// 			res.eventChannel.emit('pageData', {
					// 				drCount: 1,
					// 				data: p
					// 			});
					// 		}
					// 	});
					// }
				}
			},

			// // 显示/隐藏-出发去接客户-按钮 // 废弃
			// isGoMeetCusBtn(obj){
			// 	const that = this, luser = that.luser;

			// 	if(obj){
			// 		if(obj.status.key == 'START_TAKE_CUS'){
			// 			return false;
			// 		}else if(obj.status.key == 'DRIVER_CONFIRMED'){
			// 			//  && (!luser.curTravelOrders || luser.curTravelOrders.indexOf(obj.orderNum) == -1)
			// 			return true;
			// 		}
			// 	}
			// 	return false;
			// },
			// // 显示/隐藏-确认出行-按钮 // 废弃
			// isConfirmGoBtn(obj){
			// 	const that = this, luser = that.luser;

			// 	if(obj && obj.status.key == 'START_TAKE_CUS'){
			// 		//  && (luser.curTravelOrders && luser.curTravelOrders.indexOf(obj.orderNum) != -1)
			// 		return true;
			// 	}
			// 	return false;
			// },
			// 出发去接客户-按钮点击事件
			confirmGoMeetCus(obj) {
				const that = this,
					U = that.U,
					C = that.C;

				that.goMeetCusMd.show = true;
				that.goMeetCusMd.obj = obj;
			},
			/**
			 * 出发去接客户
			 * @param {Object} index 点击按钮下标
			 */
			goMeetCusMdClick(index) {
				const that = this,
					U = that.U,
					md = that.goMeetCusMd;
				console.log('点击的index', index);

				if (index == 0) { // 取消
					md.show = false;
				} else {
					let ps = {
						isShareLocation: index == 1 ? 0 : 1,
						orderNum: md.obj.orderNum,
						id: md.obj.id,
					};
					that.goMeetCus(ps);
				}
			},

			/**
			 * 出发去接客户
			 * @param {Object} ps json参数对象
			 */
			goMeetCus(ps) {
				const that = this,
					U = that.U,
					C = that.C,
					md = that.goMeetCusMd;;

				// 验证用户是否开启位置权限
				U.valLocationSet(function() {
					// 从缓存中获取当前位置信息
					let location = uni.getStorageSync(C.location);
					if (!location) {
						U.qinfo('获取位置失败，请重新点击');

						U.getLocation(); // 重新获取位置信息
					} else {

						ps.lnglat = location.lng + ',' + location.lat;
						console.log(JSON.stringify(ps), '----出发接客户-----')
						that.$u.api.goMeetCus(ps).then(res => {
							if (res.code != 1) {
								U.qterror(res.msg, that);

								md.show = false;
							} else {
								U.qtsuccess(res.msg, that);

								// /**********验证是否已包含当前确认订单编号，并重新保存--begin  // 废弃**************/
								// let curTravelOrders = that.luser.curTravelOrders;
								// if(curTravelOrders){
								// 	let arr = curTravelOrders.split(',');
								// 	let index = arr.findIndex(it => it == ps.orderNum);
								// 	if(index == -1) arr.push(ps.orderNum);
								// 	curTravelOrders = arr.join(',');
								// }else{
								// 	curTravelOrders = ps.orderNum;
								// }
								// // 保存订单编号至登录信息
								// let newLuser = U.scopy(that.luser);
								// newLuser.curTravelOrders = curTravelOrders;
								// // 重新保存登录信息
								// uni.setStorageSync(that.C.luser, newLuser);
								// // 重新赋值
								// that.luser = newLuser;
								// /**********验证是否已包含当前确认订单编号，并重新保存--end****************/

								// 刷新订单列表
								that.getNoOrderList(1);

								md.show = false;
							}
						});
					}
				});
			},

			// 日期选择事件回调
			selAlSeDate(e) {
				// console.log('起止日期选择事件', e);

				this.tab2.ps.startTime = e.st;
				this.tab2.ps.endTime = e.et;

				// 重新查询
				this.getAlOrderList(1);
			},
			// 获取-已完团-数据列表
			getAlOrderList(page) {
				let that = this,
					U = that.U,
					tab = that.tab2,
					ps = tab.ps;

				// 存在，则表示刷新
				if (page) {
					// 开始刷新
					tab.load.triggered = true;
					ps.page.pageNum = 1;
				}

				that.$u.api.getNoOrderList(ps).then(res => {
					// 第一页的时候，停止刷新
					if (page) {
						// 停止刷新
						tab.load.triggered = false;
						// 刷新则清空列表
						tab.list = [];
					}

					if (res && res.data) {
						let list = res.data.list;
						// 追加数据
						tab.list = tab.list.concat(list);

						let new_list = tab.list
						let indxe = 1
						let mergeMark_list = []
						for (let i = 0; i < new_list.length; i++) {
							if (new_list[i].groupNum) {
								mergeMark_list.push(new_list[i].groupNum)
							}
						}

						for (let i = 0; i < mergeMark_list.length - 1; i++) {
							for (let j = i + 1; j < mergeMark_list.length; j++) {
								if (mergeMark_list[i] == mergeMark_list[j]) {
									mergeMark_list.splice(j, 1)
									j--
								}
							}
						}
						console.log(mergeMark_list, '未完团new_list')
						console.log(new_list, '未完团new_list')
						for (let a = 0; a < new_list.length; a++) {
							if (new_list[a].groupNum) {
								for (let b = 0; b < mergeMark_list.length; b++) {
									if (new_list[a].groupNum == mergeMark_list[b]) {
										new_list[a].mergeMarkindex = b + 1
									}
								}
							}

						}

						tab.list = new_list





						// 设置总条数
						tab.total = res.data.total;

						// 设置加载状态
						tab.load.status = tab.list.length == tab.total ? 'nomore' : 'loadmore';
					}

				});

			},

		}
	};
</script>
<style lang="scss" scoped>
	.order-list {
		background: #efefef;
		overflow-y: hidden;

		// 弹框样式
		.md-content {
			padding: 10rpx;

			.my-box-shadow {
				border-radius: 12rpx;
				background: #fff;
				padding: 0 10rpx;
				box-shadow: 0 2rpx 3rpx rgba(0, 0, 0, 0.1);
			}
		}

		.tabs-wrap {
			display: flex;
			flex-direction: column;
			height: calc(100vh - var(--window-top));
			width: 100%;
			overflow-y: hidden;

			.tab-swiper-box {
				flex: 1;

				.tab-swiper-item {
					height: 100%;

					.page-box {
						padding-bottom: 80rpx;
					}
				}
			}
		}

		.no-data {
			margin-top: 50px;
		}

		.order {
			width: 710rpx;
			background-color: #ffffff;
			margin: 20rpx auto;
			border-radius: 10rpx;
			box-sizing: border-box;
			padding: 20rpx;
			font-size: 28rpx;

			.top {
				display: flex;
				justify-content: space-between;

				.left {
					display: flex;
					align-items: center;

					.store {
						margin: 0 10rpx;
						font-size: 32rpx;
						font-weight: bold;
					}
				}

				.right {
					color: $u-type-warning-dark;
				}
			}

			.item {
				display: block;
				margin: 0rpx 0 0;

				.content {
					.title {
						font-size: 28rpx;
						line-height: 50rpx;
					}

					.type {
						margin: 10rpx 0;
						font-size: 24rpx;
						color: $u-tips-color;

						.service-type {
							float: right;
						}
					}

					.delivery-time {
						color: #e5d001;
						font-size: 24rpx;
					}
				}

				.bottom {
					display: flex;
					margin-top: 20rpx;
					justify-content: flex-end;
					align-items: center;

					.btn {
						line-height: 52rpx;
						padding: 0rpx 16rpx;
						border-radius: 26rpx;
						border: 2rpx solid #ff9900;
						font-size: 26rpx;
						text-align: center;
						color: #ff9900;
						;
						margin-right: 10rpx;
					}

					.more {
						align-self: center;
						flex: 1;
						margin-right: 10rpx;
					}

					.evaluate {
						color: $u-type-warning-dark;
						border-color: $u-type-warning-dark;
					}
				}

			}

		}
	}
</style>